package net.pinnoocle.playshoppc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.group.UpdateGroup;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playdao.entity.shopPc.BaseShopSearch;
import net.pinnoocle.playdao.entity.shopPc.SaveScriptCateParams;
import net.pinnoocle.playdao.entity.shopPc.ScriptCateListPageVo;
import net.pinnoocle.playdao.entity.shopPc.ScriptCateListVo;
import net.pinnoocle.playservice.service.impl.ScriptServiceImpl;
import net.pinnoocle.playservice.service.impl.ShopServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ye
 * @Description
 * @create 2021-10-21 16:45
 */

@RestController
@RequestMapping("/scriptCate")
@Api(tags = "剧本分类管理")
public class ScriptCateController {
    @Autowired
    ScriptServiceImpl scriptService;
    @Autowired
    ShopServiceImpl shopService;

    @GetMapping("cateListWithPage")
    @ApiOperation("剧本分类列表---分页")
    public BaseResult<PageModel<ScriptCateListPageVo>> cateListWithPage(BaseShopSearch shopSearch){
        return new BaseResult<PageModel<ScriptCateListPageVo>>().ok(scriptService.cateListWithPage(shopSearch));
    }

    @GetMapping("cateList")
    @ApiOperation("剧本分类列表")
    public BaseResult<List<ScriptCateListVo>> cateList(){
        return new BaseResult<List<ScriptCateListVo>>().ok(scriptService.cateList());
    }

    @PostMapping("saveCate")
    @ApiOperation("剧本分类添加")
    public BaseResult<String> saveCate(@Validated @RequestBody SaveScriptCateParams params){
        boolean result = scriptService.saveCate(params);
        if(result){
            return new BaseResult<String>().success("剧本分类添加成功");
        }
        return new BaseResult<String>().error("剧本分类添加失败");
    }

    @PostMapping("updateCate")
    @ApiOperation("剧本分类编辑")
    public BaseResult<String> updateCate(@Validated({UpdateGroup.class}) @RequestBody SaveScriptCateParams params){
        boolean result = scriptService.updateCate(params);
        if(result){
            return new BaseResult<String>().success("剧本分类编辑成功");
        }
        return new BaseResult<String>().error("剧本分类编辑失败");
    }

    @GetMapping("deleteCate")
    @ApiOperation("剧本分类删除")
    public BaseResult<String> deleteCate(@RequestParam("cateId") Integer cateId){
        boolean result = scriptService.deleteCate(cateId);
        if(result){
            return new BaseResult<String>().success("剧本分类删除成功");
        }
        return new BaseResult<String>().error("剧本分类删除失败");
    }
}
